using System;
using System.Collections.Generic;
using System.Text;
using Calc.Execution;

namespace Calc.Operations
{
	/// <summary>
	/// A special type of operand for representing parenthesised segments
	/// </summary>
	public class Parenthesese : IOperand
	{
		protected IOperand _operation;

		public Parenthesese() : this(null)
		{
				
		}

		public Parenthesese(IOperand operation)
		{
			_operation = operation;
		}

		public IOperand Operation
		{
			get { return _operation; }
			set { _operation = value; }
		}

		public double GetValue(ExecutionContext context)
		{
			if ( _operation == null )
				throw new ArgumentNullException("Operation", "Operation is null, so a calculation is not possible");

			return _operation.GetValue(context);
		}

		public override string ToString()
		{
			string oper = "";
			if ( _operation != null )
				oper = _operation.ToString();

			return "(" + oper + ")";
		}
	}
}
